From 7d0f25c177e2f39c9222bd7b3bdc46d87e294b8b Mon Sep 17 00:00:00 2001 From: robertlipe Date: Thu, 28 Feb 2013 13:39:24 +0000 Subject: [PATCH] xiao jian cheng adds Mapbar support. --- gpsbabel/Makefile.in | 2 +- gpsbabel/mapbar_track.cc | 150 ++++++++++++++++++++++ gpsbabel/reference/track/mapbar.trk | Bin 0 -> 860 bytes gpsbabel/reference/track/mapbar~gpx.gpx | 163 ++++++++++++++++++++++++ gpsbabel/src/core/datetime.h | 3 + gpsbabel/testo.d/mapbar.test | 4 + gpsbabel/vecs.cc | 7 + 7 files changed, 328 insertions(+), 1 deletion(-) create mode 100644 gpsbabel/mapbar_track.cc create mode 100644 gpsbabel/reference/track/mapbar.trk create mode 100644 gpsbabel/reference/track/mapbar~gpx.gpx create mode 100644 gpsbabel/testo.d/mapbar.test diff --git a/gpsbabel/Makefile.in b/gpsbabel/Makefile.in index 6d673b223..98fb41dfe 100644 --- a/gpsbabel/Makefile.in +++ b/gpsbabel/Makefile.in @@ -83,7 +83,7 @@ ALL_FMTS=$(MINIMAL_FMTS) gtm.o gpsutil.o cetus.o copilot.o \ pocketfms_bc.o pocketfms_fp.o pocketfms_wp.o naviguide.o enigma.o \ vpl.o teletype.o jogmap.o bushnell.o bushnell_trl.o wintec_tes.o \ subrip.o garmin_xt.o garmin_fit.o lowranceusr4.o \ - mtk_locus.o googledir.o + mtk_locus.o googledir.o mapbar_track.o FMTS=@FMTS@ diff --git a/gpsbabel/mapbar_track.cc b/gpsbabel/mapbar_track.cc new file mode 100644 index 000000000..da21a2489 --- /dev/null +++ b/gpsbabel/mapbar_track.cc @@ -0,0 +1,150 @@ +/* + China mapbar navigation track reader for sonim xp3300 + it's maybe can used in other demo devices of mapbar navigation + + Copyright (C) 2013 xiao jian cheng, azuresky.xjc@gmail.com + Copyright (C) 2001-2013 Robert Lipe, robertlipe@gpsbabel.org + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA + + */ + +#include "defs.h" +#include + +#define MYNAME "mapbar_track" + +static gbfile* fin; + +static +arglist_t mapbar_track_args[] = { + ARG_TERMINATOR +}; + +/******************************************************************************* +* %%% global callbacks called by gpsbabel main process %%% * +*******************************************************************************/ + +static void +mapbar_track_rd_init(const char* fname) +{ + fin = gbfopen(fname, "r", MYNAME); +} + +static void +mapbar_track_rd_deinit(void) +{ + gbfclose(fin); +} + +static gpsbabel::DateTime +read_time_t(void) +{ + int hour = gbfgetint16(fin); + int min = gbfgetint16(fin); + int sec = gbfgetint16(fin); + int year = gbfgetint16(fin); + int mon = gbfgetint16(fin); + int mday = gbfgetint16(fin); + gpsbabel::DateTime t(QDate(year, mon, mday), QTime(hour, min, sec)); +// qDebug() << t; + return t; +} + +static const double DIV_RATE = 100000.0f; +static waypoint* +read_waypoint(void) +{ + int longitude = gbfgetint32(fin); + int latitude = gbfgetint32(fin); + + waypoint* ret = waypt_new(); + + ret->latitude = double(latitude)/DIV_RATE; + ret->longitude = double(longitude)/DIV_RATE; + + return ret; +} + +static void +mapbar_track_read(void) +{ + route_head* track = route_head_alloc(); + is_fatal((track == NULL), MYNAME ": memory non-enough"); + track_add_head(track); + + time_t start_time = read_time_t(); + (void) start_time; // currently not used. + time_t end_time = read_time_t(); + (void) end_time; // currently not used. + + char name[200] = {0}; + gbfread((void*)name, 1, 200, fin); + // At this point, name is a UCS-16 encoded, zero terminated string. + // All our internals use UTF-8 encoding, so convert now. + int olen = strlen(name); + track->rte_name = cet_str_uni_to_utf8((const short int*) name, olen); + + waypoint* start = read_waypoint(); + track_add_wpt(track, start); + + waypoint* end = read_waypoint(); + + // skip one pair waypoint + gbfseek(fin, 4*4, SEEK_CUR); + // skip way length + gbfseek(fin, 8, SEEK_CUR); + // skip fixed value + gbfseek(fin, 4, SEEK_CUR); + + int end_flag = gbfgetint32(fin); + for (;;) { + int length = gbfgetint32(fin); + is_fatal((length < 1) || (length > 1600), MYNAME ": get bad buffer length"); + + length += 16; // the real length + is_fatal((length % 8 != 0), MYNAME ": bad buffer size"); + + const int amount = length/8; + for (int i = 0; i < amount; ++i) { + waypoint* tmp = read_waypoint(); + track_add_wpt(track, tmp); + } + + if (end_flag) { + break; + } + end_flag = gbfgetint32(fin); + } + + track_add_wpt(track, end); +} + +// capabilities below means: we can only read trackpoints. + +ff_vecs_t mapbar_track_vecs = { + ff_type_file, + { ff_cap_none, (ff_cap)(ff_cap_read), ff_cap_none }, + mapbar_track_rd_init, + NULL, + mapbar_track_rd_deinit, + NULL, + mapbar_track_read, + NULL, + NULL, + mapbar_track_args, + CET_CHARSET_UTF8, 0 + /* not fixed, can be changed through command line parameter */ +}; diff --git a/gpsbabel/reference/track/mapbar.trk b/gpsbabel/reference/track/mapbar.trk new file mode 100644 index 0000000000000000000000000000000000000000..c08ca5d6e0e8ed1aa3ed38ecc5b1bbff6eade60a GIT binary patch literal 860 zcmd7Q&nts*9Ki99Np_GX2PI0agc75b77De?C@lxtj%zN;&-|!Srbw;Gk2RW=kYAfn zR#UQ8OB^{lXs#|!?z}&FcJdE+>Umzz_w#(dKR!>NVsS`?ycL^xnx#bQjrVcybfnqs z4D~Nw1x1>qMOvjsY+@(hE^RzD^8c@oTwET!RylZ&i`iop9T(v%<459=!rvMij8ZHn z`ID1hibA&;>z!}uK{HS#e;XS%AgB_T{M%27&yvB0W`Pwu29x9+$EZo`` O+EW_W9?SPhKJN#1^!8o= literal 0 HcmV?d00001 diff --git a/gpsbabel/reference/track/mapbar~gpx.gpx b/gpsbabel/reference/track/mapbar~gpx.gpx new file mode 100644 index 000000000..cf39daa11 --- /dev/null +++ b/gpsbabel/reference/track/mapbar~gpx.gpx @@ -0,0 +1,163 @@ + + + + + + 山顶到豆腐花 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/gpsbabel/src/core/datetime.h b/gpsbabel/src/core/datetime.h index c62baa408..9aad0368d 100644 --- a/gpsbabel/src/core/datetime.h +++ b/gpsbabel/src/core/datetime.h @@ -43,6 +43,9 @@ public: t_ = -1; } + DateTime(QDate date, QTime time) : QDateTime(date, time) { } + + // Handle time_tm tm = wpt->creation_time; operator const time_t() const { return this->toTime_t(); diff --git a/gpsbabel/testo.d/mapbar.test b/gpsbabel/testo.d/mapbar.test new file mode 100644 index 000000000..a91ac066d --- /dev/null +++ b/gpsbabel/testo.d/mapbar.test @@ -0,0 +1,4 @@ +# Mapbar/Sonim XP330 +rm -f ${TMPDIR}/mapbar.gpx +gpsbabel -i mapbar -f ${REFERENCE}/track/mapbar.trk -o gpx -F ${TMPDIR}/mapbar.gpx +compare ${REFERENCE}/track/mapbar~gpx.gpx ${TMPDIR}/mapbar.gpx diff --git a/gpsbabel/vecs.cc b/gpsbabel/vecs.cc index 6ee045ad7..55d30e4db 100644 --- a/gpsbabel/vecs.cc +++ b/gpsbabel/vecs.cc @@ -179,6 +179,7 @@ extern ff_vecs_t wintec_tes_vecs; extern ff_vecs_t subrip_vecs; extern ff_vecs_t format_garmin_xt_vecs; extern ff_vecs_t format_fit_vecs; +extern ff_vecs_t mapbar_track_vecs; static vecs_t vec_list[] = { @@ -1067,6 +1068,12 @@ vecs_t vec_list[] = { "Flexible and Interoperable Data Transfer (FIT) Activity file" "fit" }, + { + &mapbar_track_vecs, + "mapbar", + "Mapbar (China) navigation track for Sonim Xp3300", + "trk" + }, #endif // MAXIMAL_ENABLED { NULL, -- 2.30.2